<template>
    <div class="addressContainer">
        <el-tabs v-model="currentLabel" @tab-change="changeHandler" tab-position="left" class="tabs">
            <el-tab-pane
                v-for="item in addressItems"
                :label="item.label"
                :name="item.label"
                :key="item.id"
            ></el-tab-pane>
        </el-tabs>
        <div class="content">
            <component :is="currentComponent" />
        </div>
    </div>
</template>

<script>
import AddressForm from "@/components/Address/AddressForm.vue";
import ManageAddress from "@/components/Address/ManageAddress.vue";

export default {
    name: "AddressView",
    components: {
        AddressForm,
        ManageAddress,
    },
    data() {
        return {
            currentLabel: "地址管理",
            currentComponent: "ManageAddress",
            addressItems: [
                {
                    id: 2,
                    label: "地址管理",
                    component: "ManageAddress",
                },
                {
                    id: 1,
                    label: "添加地址",
                    component: "AddressForm",
                },
            ],
        };
    },
    methods: {
        changeHandler(label) {
            // console.log(label);
            const item = this.addressItems.filter((item) => item.label === label)[0].component;
            this.currentComponent = item;
        },
    },
};
</script>

<style lang="scss" scoped>
.addressContainer {
    width: 80%;
    margin: 0 auto;
    display: flex;

    .tabs {
        height: 70vh;
    }

    .content {
        width: 80%;
        margin: 0 auto;
        margin-top: 2rem;
    }
}
</style>
